// ============================================================================
//
// Graph framework by Aurelien Moreau aurelien.moreau@gmail.com
// Modified by Pierre CHATEL chatelp@gmail.com
// Distributed under LGPL
// Copyright (C) Aurelien Moreau, 2008, 2009. All rights reserved
//
// ============================================================================

package com.thalesgroup.graphFramework.algorithms;

import java.util.LinkedList;
import java.util.List;

import com.thalesgroup.graphFramework.core.Vertex;


public class LeastPathCost {

	public static final String W = "net.yienyien.graph.algo.LeastPathCost.feature.w";
	public static final String PI = "net.yienyien.graph.algo.LeastPathCost.feature.pi";

	static public double getShortestPathCost(final Vertex<?, ?> tgt) {
		return (Double) tgt.getUserFeature(W);
	}

	@SuppressWarnings("unchecked")
	static public <V, E> List<Vertex<V, E>> getShortestPath(
			final Vertex<V, E> tgt) {
		final LinkedList<Vertex<V, E>> result = new LinkedList<Vertex<V, E>>();
		Vertex<V, E> pr = tgt;
		while (pr != null) {
			result.addFirst(pr);
			pr = (Vertex<V, E>) pr.getUserFeature(PI);
		}

		return result;
	}

}
